<?php 
/*
 * FQL Builder
 *
 * http://fql-builder.mariogarcia.biz
 * http://www.facebook.com/mariogarcia.ar 
 *
 * Copyright (c) 2011 - 2012 Mario Garcia
 *
 * 
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 */
$table_name = $_POST['table_name'];
$fql_reference = unserialize(file_get_contents('fql-reference.serialize'));

// print_r($fql_reference);exit;
$table = $fql_reference[$table_name];
?>
<div class='wd-fb-table' customtitle='<?=$table['name']?>' >
    <div class="hidden">
        <div class="wd-fb-help" id="wd-fb-id-<?=$table['name']?>">
            <?=$table['name']?><hr >
            <?=$table['content']?><br>
            Permissions: <? $perms = count($table['permissions'])?join(', ',$table['permissions']):''; echo $perms?>
        </div>
    </div>

    <div class="wd-fb-table-header">
        <?=$table['name']?> 
        <?php if($perms){ ?>
        <span class='wd-fb-table-perm'><a href="data/add-perms.php?perms=<?=$perms?>">p</a></span>
        <?php } ?>
        <span class='wd-fb-table-link' title="Goto <?=$table['link']?>"><a target="_blank" href='<?=$table['link']?>'>i</a></span>
        <span class='wd-fb-table-help'><a href="#wd-fb-id-<?=$table['name']?>">?</a></span>
        <span class='wd-fb-table-build'>b</span> 
        <span class='wd-fb-table-min'>_</span>
    </div>
    
    
    <div class="wd-fb-table-panel">
        <table class="wd-fb-table-table">
        <thead>
            <tr>
                <th title='help'>&nbsp;</th>
                <th><input type="checkbox" class='wd-fb-table-all'></th>
                <th title='indexable'>&nbsp;</th>
                <th style="text-align:left;">(All columns)</th>
            </tr>
        </thead>
        
        
        
        <tbody>
        <?php foreach($table['fields']['name'] as $k=>$f){ 
            $indexable = $table['fields']['indexable'][$k]!=''?'fb-checkbox-indexable':'';
            ?>
            <tr>
                <td><a href="#fb-table-help-<?=$f?>">?</a> <div class="hidden"><div id="fb-table-help-<?=$f?>"><b><?=$table['fields']['type'][$k]?></b><?=$table['fields']['desc'][$k]?></div></div> </td>
                
                <td><input type="checkbox" class="fb-checkbox <?=$indexable?>" value='<?=$f?>' name='fields[]'></td>
                <td><?=$table['fields']['indexable'][$k]?></td>
                <td><?=$f?></td>
            </tr>
        <?php } ?>
        </tbody>
        </table>
    </div> 
</div>